package com.xuxin.baby.utils;

import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.StringUtils;
import com.xuxin.baby.activity.SplashActivity;
import com.xuxin.baby.database.DBControl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xu_xin
 * Created on 2020/11/20 0020
 */
public class BaseUtils {

    /**
     * 处理文章正文<p><p/>
     */
    public static String dispose(String content) {
        if (!StringUtils.isEmpty(content)) {
            String message = RegexUtils.getReplaceAll(content, "<p>", "");
            message = RegexUtils.getReplaceAll(message, "</p>", "\n");
            return message;
        } else {
            return "";
        }
    }

    /**
     * 处理时间
     */
    public static String getTime(String time) {
        if (!StringUtils.isEmpty(time)) {
            return time.replaceAll("T(.*)", "");
        } else {
            return "";
        }
    }

    /**
     * 退出登录
     */
    public static void loginExit(Context context) {
        DBControl.deleteAllSearch();
        DBControl.deleteAllHistory();
        DBControl.deleteAllCart();
        ACache.get(context).clear();
        Intent intent = new Intent(context, SplashActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        ActivityUtils.finishAllActivities();
        ActivityUtils.startActivity(intent);
    }

    public static List<String> getMenu() {
        List<String> list = new ArrayList<>();
        list.add("科学喂养");
        list.add("大小便");
        list.add("睡眠");
        list.add("生长发育");
        list.add("早期教育");
        list.add("常见护理问题与常见病的预防及家庭处理");
        list.add("预防免疫接种");
        list.add("预防意外伤害");
        list.add("口腔保健");
        list.add("中医调理");
        list.add("妈妈的合理膳食");
        list.add("旅游医药百宝箱");
        return list;
    }
}